import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

wd = webdriver.Chrome(service=Service(f".\chromedriver_win136.exe"))
"""
wd.get("https://www.baidu.com")
element = wd.find_element(By.ID, "kw")
element.send_keys("今天天气")
time.sleep(5)
element = wd.find_element(By.LINK_TEXT, "网盘")
element.click()
elements = wd.find_elements(By.TAG_NAME, "meta")
"""
wd.get("https://pvp.qq.com/web201605/herolist.shtml")
time.sleep(1)
element = wd.find_element(By.ID, "search")
time.sleep(1)
# element.send_keys("曹操")
# time.sleep(5)
# heros = wd.find_elements(By.CLASS_NAME, "herolist")
# print(heros[0].get_attribute("outerHTML"))

# 获取英雄列表中所有英雄名字
# 获取英雄列表中指定英雄

heros = wd.find_elements(By.CSS_SELECTOR, ".herolist > li:nth-child(5)")

print(len(heros))
for h in heros:
    print(h.text)

heros[0].click()

time.sleep(2)
all_window = wd.window_handles
wd.switch_to.window(all_window[1])
wd.execute_script("window.scrollTo(0,400)")
# 获取该英雄的技能列表
time.sleep(2)
skill_names = wd.find_elements(By.CSS_SELECTOR, ".show-list > p > b")
print(len(skill_names))

for s in skill_names[0:4]:
    print(s.get_attribute("innerHTML"))
# 获取该英雄所有技能的消耗值
sps = wd.find_elements(By.CSS_SELECTOR, ".show-list > p > span:nth-child(3)")
for sp in sps:
    # 注意这里是全角的冒号
    print(sp.get_attribute("innerHTML").strip().split("：")[1])

time.sleep(15)
